using System;
using infoMECHANICA.NHibernateORM.CriteriaBuilder;

namespace infoMECHANICA.NHibernateORM.TestMappings
{
    /// <summary>
    /// Recorder of Company class/Companies table
    /// </summary>
    [Serializable]
    public class CompanyRec : CriteriaRecorder<CompanyRec,Company>
    {
        private ICriterionProperty<int> _CompanyId;
        private ICriterionProperty<string> _Name;
        private CountryRec _CountryRec;
        private ICriterionProperty<string> _City;
        private ISubcriteriaProperty<EmployeeRec> _EmployeesByCompany;


        /// <summary>
        /// Recorder property for CompanyId column (PRIMARY KEY!)
        /// </summary>
        public ICriterionProperty<int> CompanyId
        {
            get 
            {
                if (this._CompanyId == null)
                {
                    this._CompanyId = new CriterionProperty<int>("CompanyId", this);
                }
                
                return _CompanyId; 
            }               
        }
        
        /// <summary>
        /// Gets the name of dto identifier property (when it's different than "Id")
        /// </summary>
        public override string GetIdPropertyName()
        {
            return "CompanyId";
        }
 
        /// <summary>
        /// Recorder property for Name column
        /// </summary>
        public ICriterionProperty<string> Name
        {
            get 
            {
                if (this._Name == null)
                {
                    this._Name = new CriterionProperty<string>("Name", this);
                }
                
                return _Name; 
            }               
        }        
 
        /// <summary>        
        /// Recorder for one-to-many relations between Countries and Companies
        /// </summary>        
        public virtual CountryRec Country        
        {
            get
            {
                if (this._CountryRec == null)
                {
                    this._CountryRec = new CountryRec(this);
                }
                
                return this._CountryRec;
            }
            set
            {
                if (this._CountryRec == null)
                {                    
                    this._CountryRec = value;
                }
                else
                {
                    throw new RecorderAlreadyCreatedException();
                }
            }
        }
 
        /// <summary>
        /// Recorder property for City column
        /// </summary>
        public ICriterionProperty<string> City
        {
            get 
            {
                if (this._City == null)
                {
                    this._City = new CriterionProperty<string>("City", this);
                }
                
                return _City; 
            }               
        }        


        /// <summary>
        /// Recorder property of many-to-many relationship between Employees and Companies tables
        /// </summary>        
        public virtual ISubcriteriaProperty<EmployeeRec> EmployeesByCompany
        {
            get
            {
                if (this._EmployeesByCompany == null)
                {
                    this._EmployeesByCompany = new SubcriteriaProperty<EmployeeRec>("Company");
                }
                
                return _EmployeesByCompany;         
            }
        }        

        /// <summary>
        /// Constructor, creates the recorder with no parent
        /// </summary>
        public CompanyRec()
        {
        }
        
        /// <summary>
        /// Constuctor, creates CriteriaRecorder and sets its parent
        /// </summary>
        /// <param name="parent">Parent of this recorder</param>
        public CompanyRec (ICriteriaRecorder parent)
            : base(parent)
        {
        }
    }
}